/**
 * 
 */
package com.cqan.tuan.parser;

import java.io.File;
import java.net.URL;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.io.SAXReader;

import com.cqan.exception.AppException;
import com.cqan.tuan.entity.BaseEntity;

/**
 * @author slaton
 *
 * 
 * 2012-12-1上午11:36:20 created
 */
public abstract class XmlParser implements Parser {

	private static SAXReader saxReader = new SAXReader();
	
	@Override
	public List<BaseEntity> parser(String url) throws AppException {
		try {
			URL xmlurl = new URL(url);
			Document doc = saxReader.read(xmlurl);
			return analyze(doc);
		} catch (Exception e) {
			e.printStackTrace();
			throw new AppException(e.getMessage());
		}
	}

	
	@Override
	public List<BaseEntity> parser(File file)throws AppException{
		try {
			Document doc = saxReader.read(file);
			return analyze(doc);
		} catch (Exception e) {
			e.printStackTrace();
			throw new AppException(e.getMessage());
		}
	}
	
	abstract List<BaseEntity> analyze(Document doc)throws AppException;

}
